﻿namespace nGo.Web.Mvc.Examples.Controllers

open System
open System.ComponentModel.DataAnnotations
open System.Web.Mvc
open System.Web.Http

open nGo.Models
open nGo.Web.Mvc.Controllers

type MyModel(name) = 
    member x.Name with get() = name

type MyModelRequest() = 
    let mutable name = ""
    [<Required>]
    member x.Name with get() = name and set(value) = name <- value

type MyNewModel(name) = 
    member x.Name with get() = name

type MyService() =
    inherit ModelProvider<MyModel>()    
    override x.GetModel() = MyModel("F# dude")

type MyNewService() =
    inherit ModelProvider<MyModelRequest, MyNewModel>()    
    override x.GetModel(req) = MyNewModel("New " + req.Name)

type HomeController() =
    inherit ControllerBase()
    
    member x.Index() = x.HandleViewAction<MyModel>()

    member x.Some(request:MyModelRequest) = x.HandleViewAction<MyModelRequest, MyNewModel>(request, "Index")

type ModelsController() =
    inherit ApiController()
    
    member x.GetAllModels() = [|MyModel("Hello F# API")|]
    
    member x.GetModel(name:string) = MyModel("Hello F# API")